#ifndef WAVEFORMCHART_H
#define WAVEFORMCHART_H

#include <QtCharts/QChartView>
#include <QtCharts/QLineSeries>
#include <QtCharts/QValueAxis>
#include <QScrollBar>
#include <QMouseEvent>
#include <QWheelEvent>
#include <QRubberBand>
#include "QPushButton"

class WaveformChart : public QChartView {
    Q_OBJECT

public:
    explicit WaveformChart(int SampleRate = 250,int seriesNum=1,QWidget *parent = nullptr);
    ~WaveformChart();
    void addDataPoint(double x, double y); // 添加数据点

    void setSerialNames(QString name1, QString name2, QString name3);
    void addData1Points(QList<int>x, QList<double>y);
    void addData2Points(QList<int>x,QList<double>y);
    void addData3Points(QList<int>x,QList<double>y);
    void addDataPoints(QList<QPointF> &points);
protected:
    // void wheelEvent(QWheelEvent *event) override; // 鼠标滚轮事件
    // void mouseMoveEvent(QMouseEvent *event) override; // 鼠标拖动事件
    // void mousePressEvent(QMouseEvent *event) override; // 鼠标按下事件

private slots:
    void onScrollBarValueChanged(int value); // 滚动条值改变事件

    void onclicked();
    void onColorButtonClicked();
    // void updateXAxisLabels();
private:
    QChart *chart; // 图表
    QChartView *chartView;
    QPushButton *bt_full;//全程显示
    QPushButton *colorButton;
    QRubberBand *rubberBand;
    QLineSeries *series; // 波形数据系列
    QLineSeries *series_f1; // 波形特征点序列
    QLineSeries *series_f2; // 波形特征点序列
    QValueAxis *xAxis; // X 轴
    QValueAxis *yAxis; // Y 轴
    QScrollBar *scrollBar; // 滚动条
    QPoint lastMousePos; // 鼠标上一次的位置
    bool eventFilter(QObject *obj, QEvent *event);
    QPoint selectionStart;
    int _SampleRate,_seriesNum;
    double maxv,minv;
    int SampleNum;
    // QString formatXAxisLabel(qreal value);

};

#endif // WAVEFORMCHART_H

